<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.List" %>
<%@ page import="dto.OperatoerDTO" %>
<%@ page import="dto.ProduktBatchDTO" %>
<jsp:useBean id="func" class="Function.Functions" scope="session"></jsp:useBean>
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="style.css">
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>Edit Produkt Batch</title>
	</head>
<body>
<div id="Centring">
<div class="sidenavn">Produkt Batches</div>
<div id="Top"><div class="menu">
			<form method="POST">
				<table width=100%> 
					<tr>
						<td>
						<%= session.getAttribute("menu") %>
						</td>
						<td align="right">
						<% 
						OperatoerDTO tempOpr = (OperatoerDTO)session.getAttribute("loginID");
						%>
						<input type="submit" name="link" value="Edit Profile" class="hyperlinkButton" size=1>
						<input type="submit" name="link" value="log out" class="hyperlinkButton">
						</td>
					</tr>
				</table>
			</form>
</div></div>
<div id="Main">
	<br>
	<hr width=95% border=1>
	<br>
	<div class="Titlelille">Edit Produkt Batch</div>
	Indtast nye informationer og tryk edit
	<div class="Indhold">	
	
<form method="POST">
<%
int pbNrE = Integer.parseInt(session.getAttribute( "pbNr" ).toString());
List<ProduktBatchDTO> tempE = func.getProduktBatchListNr(pbNrE);
 
if(request.getMethod().equals("POST") && request.getParameter("action").matches("Delete Produkt")){
	func.deleteProduktBatch(Integer.parseInt(session.getAttribute("pbNr").toString()));

}else if(request.getMethod().equals("POST")) {
		String value1 = request.getParameter("action");
		String[] value = value1.split("\\.");
	
	if(value[0].matches("Edit")){
		out.print("<br><br>");
			out.print("<table id=\"tabledesign\" align=center>");
			out.print("<tr>");
			out.print("<th>Recept Id</th>");
			out.print("<th>Status</th>"); 
			out.print("<th>Netto</th>");
			out.print("<th>Submit</th>");
			out.print("</tr>");
				out.print("<tr>");
  				out.print("<td>"+"<input type=\"text\" name=\"receptId\" value=\"\">"+"</td>");
  				out.print("<td>"+"<select name=\"status\">");
  				out.print("<option value=0 selected>0</option>");
				out.print("<option value=1>1</option>");
				out.print("<option value=2>2</option>");
				out.print("</select></td>");
  				out.print("<td>"+"<input type=\"text\" name=\"Netto\" value=\"\">"+"</td>");
  				out.print("<td>"+"<button type=\"Submit\" name=\"action\" value=\"Submit."+value[1]+"\" class=\"hyperlinkButton\">SAVE</button></td>");
  				out.print("</tr>");
  			out.print("</table>");
	
	}else if(value[0].matches("Submit")){
		try{
			int pbId = tempE.get((Integer.parseInt(value[1].toString())-1)).getPbId();
			int receptId = Integer.parseInt(request.getParameter("receptId"));
			int status = Integer.parseInt(request.getParameter("status"));
			int oprId = tempE.get((Integer.parseInt(value[1].toString())-1)).getoprId();
			int rbId = tempE.get((Integer.parseInt(value[1].toString())-1)).getrbId();
			double tara = tempE.get(Integer.parseInt(value[1].toString())-1).gettera();
			double netto = Double.parseDouble(request.getParameter("Netto"));
			String startTid = tempE.get(Integer.parseInt(value[1].toString())-1).getstartTid();
			String slutTid = tempE.get(Integer.parseInt(value[1].toString())-1).getslutTid();
			func.updateProduktBatch(new ProduktBatchDTO(pbId,receptId,status,oprId,rbId,tara,netto,startTid,slutTid));
		}catch(Exception e){
			out.print("<p style=\"color:red;\">Invalid Input</p>");
		}	
	}
	}
	

%>

<%
int pbNr = Integer.parseInt(session.getAttribute("pbNr").toString());
List<ProduktBatchDTO> temp = func.getProduktBatchListNr(pbNr);
String listArray[][];
listArray = new String[temp.size()][9];

	for(int i=0;i<temp.size();i++){
		listArray[i][0] = Integer.toString(temp.get(i).getPbId());
		listArray[i][1] = Integer.toString(temp.get(i).getReceptId());
		listArray[i][2] = Integer.toString(temp.get(i).getStatus());
		listArray[i][3] = Integer.toString(temp.get(i).getoprId());
		listArray[i][4] = Integer.toString(temp.get(i).getrbId());
		listArray[i][5] = Double.toString(temp.get(i).gettera());
		listArray[i][6] = Double.toString(temp.get(i).getnetto());
		listArray[i][7] = temp.get(i).getstartTid();
		listArray[i][8] = temp.get(i).getslutTid();

		}

	out.print("<br>");
	out.print("<table id=\"tabledesign\" align=center width=100% >");
	out.print("<tr>");
	out.print("<th>Pb Id</th>");
	out.print("<th>Recept Id</th>");
	out.print("<th>Rb Id</th>");
	out.print("<th>Status</th>");
	out.print("<th>Tera</th>");
	out.print("<th>Netto</th>");
	out.print("<th>Valg</th>");
	out.print("</tr>");
	for(int i=0;i<temp.size();i++){
		out.print("<tr>");
		out.print("<td>"+listArray[i][0]+"</td>"); 
		out.print("<td>"+listArray[i][1]+"</td>"); 
		out.print("<td>"+listArray[i][4]+"</td>");
		out.print("<td>"+listArray[i][2]+"</td>");
		out.print("<td>"+listArray[i][5]+"</td>");
		out.print("<td>"+listArray[i][6]+"</td>"); 
		out.print("<td> <button type=\"submit\" name=\"action\" value=\"Edit."+(i+1)+"\" class=\"hyperlinkButton\">EDIT</button> </td>");
		out.print("</tr>");
		}
	out.print("</table>");
	out.print("<CENTER>");
	if(tempOpr.getRights().equals("admin"))
		out.print("<br>"+"<input type=submit name=action value=\"Delete Produkt\">");
	out.print("</CENTER>");

%>


</form>
<br>
</div>
</div>
<div id="Bund"></div>


</div>	
</body>
</html>
//int pbId,int receptId,int status,int oprId,int rbId,int tara,int netto,String startTid,String slutTid
